'''
    Utilities modules
'''

from random import randint, choice
from string import ascii_lowercase, digits
from scapy.all import Ether, ARP, srp1

def getRandomPort():
    blacklisted = [53]
    port = randint(1023, 65535)

    while port in blacklisted:
        port = randint(1023, 65535)

    return port

def getRandomSubdomain():
    return ''.join(choice(ascii_lowercase + digits) for _ in range(10)) + '.'

def getRandomTXID():
    return randint(0, 65535)

def getRandomIPv4():
    return '.'.join('%s' %randint(0,255) for _ in xrange(4))

def getMAC(ip):
    pkt = Ether() / ARP(op=ARP.who_has, pdst=ip)
    ans = srp1(pkt, verbose=False, timeout=10)
    if ans[ARP] and ans[ARP].hwsrc:
        return ans[ARP].hwsrc
    else:
        return None
